//
//  HomePageCollectionCell.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/20.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

class HomePageCollectionCell: UICollectionViewCell {
    var scaleImageView:UIImageView = UIImageView.init()
    var nameLabel:UILabel = UILabel.init()
    var addNameLabel:UILabel = UILabel.init()
    var progressView:UIProgressView = UIProgressView.init()
    var needLabel:UILabel = UILabel.init()
    var immediaButton:UIButton = UIButton.init()
    var model:HomePageProductModel?{
        didSet{
            //布局
            //        cell.nameLabel.text = "芝士蛋糕2016最新款水果味芝士蛋糕"
            //        cell.addNameLabel.text = "合肥世纪景园小区"
            //        cell.progressView.progress = 0.6
            //        cell.needLabel.text = "还需要56人参与"
            self.nameLabel.text = self.model?.productName
            self.addNameLabel.text = self.model?.storeName
            self.progressView.progress = (self.model?.progress)!
            self.needLabel.text = "还需"+(self.model?.needPerson)! + "人参与"
            self.scaleImageView.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.right.equalTo(-16)
                make.top.equalTo(12)
                make.height.equalTo(3*(k_Wide/2)/4)
            }
            self.nameLabel.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.right.equalTo(-16)
                make.top.equalTo(self.scaleImageView.snp.bottom).offset(12)
                make.height.equalTo(40)
            }
            self.addNameLabel.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.right.equalTo(-16)
                make.top.equalTo(self.nameLabel.snp.bottom).offset(8)
                make.height.equalTo(16)
            }
            self.progressView.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.right.equalTo(-16)
                make.height.equalTo(8)
                make.top.equalTo(self.addNameLabel.snp.bottom).offset(8)
            }
            self.immediaButton.snp.makeConstraints { (make) in
                make.right.equalTo(-16)
                make.width.equalTo(self.addNameLabel.width(forText: "立即参与", withFontSize: 14, withTextHeight: 15))
                make.top.equalTo(self.progressView.snp.bottom).offset(6)
                make.height.equalTo(20)
            }
            self.needLabel.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.height.equalTo(16)
                make.right.equalTo(self.immediaButton.snp.left).offset(0)
                make.top.equalTo(self.progressView.snp.bottom).offset(8)
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setUI()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
extension HomePageCollectionCell{
    func setUI(){
        self.contentView.backgroundColor = .white
       self.contentView.addSubview(self.scaleImageView)
        self.contentView.addSubview(self.nameLabel)
        self.contentView.addSubview(self.addNameLabel)
        self.contentView.addSubview(self.progressView)
        self.contentView.addSubview(self.needLabel)
        self.contentView.addSubview(self.immediaButton)
        self.nameLabel.font = UIFont.systemFont(ofSize: 16)
        self.addNameLabel.font = UIFont.systemFont(ofSize: 12)
        self.addNameLabel.textColor = .gray
        self.needLabel.font = UIFont.systemFont(ofSize: 12)
        self.immediaButton.setTitle("立即参与", for: .normal)
        self.immediaButton.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        self.immediaButton.layer.cornerRadius = 5.0
        self.immediaButton.layer.borderWidth = 1.0
        self.immediaButton.layer.borderColor = UIColor.red.cgColor
        self.immediaButton.setTitleColor(.red, for: .normal)
        self.needLabel.textColor = BaseFontColor
        self.nameLabel.numberOfLines = 0
        self.progressView.progressTintColor = .orange
        self.scaleImageView.backgroundColor = .black
    }
}
